import requests
import re, time
from lxml import etree
print('hello')
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
}
# content = requests.get('https://book.douban.com/latest?icn=index-latestbook-all', headers=headers).text

# pattern = re.compile('<li.*?detail-frame.*?<h2>.*?<a href="(.*?)">(.*?)</a>.*?<span.*?font-small.*?>(.*?)</span>.*?<p.*?color-gray.*?>(.*?)</p>.*?<p\sclass="detail">(.*?)</p>', re.S)
# pattern = re.compile('<li.*?cover">.*?<a href="(.*?)" title="(.*?)"></a>', re.S)
# result = re.findall(pattern, content)
url = 'http://www.yyfdc.com.cn/lpxq.aspx?id=1673'
s = requests.Session()
content = s.get(url = url, headers=headers)
cookie = content.cookies.get_dict()
html = content.text

xpt = etree.HTML(html)
__VIEWSTATEGENERATOR = xpt.xpath('//input[@id="__VIEWSTATEGENERATOR"]/@value')[0]
__VIEWSTATE = xpt.xpath('//input[@id="__VIEWSTATE"]/@value')[0]
__EVENTTARGET = 'WebChessTabForSqlCtl1'
__EVENTARGUMENT = "kind=click&amp;row=3&amp;col=2&amp;text=501&amp;sid=120562"
__EVENTVALIDATION = xpt.xpath('//input[@id="__EVENTVALIDATION"]/@value')[0]

datas = {
    '__VIEWSTATE': __VIEWSTATE,
    '__VIEWSTATEGENERATOR': __VIEWSTATEGENERATOR,
    '__EVENTTARGET': __EVENTTARGET,
    '__EVENTARGUMENT': __EVENTARGUMENT,
    '__EVENTVALIDATION': __EVENTVALIDATION,
    'WebChessTabForSqlCtl1': ''
}
headers = dict(headers, **cookie)
ps = s.post(url = url, data = datas, cookies=cookie, headers=headers)
time.sleep(3)
res = s.get(url = 'http://www.yyfdc.com.cn/RoomInfo.aspx', headers=headers, cookies=cookie)
print('==='*100)
print(res.text)
print(content.cookies.get_dict())
print(ps.cookies.get_dict())
print(res .cookies.get_dict())

